package com.blog.quartzTest;

import org.quartz.JobDetail;
import org.quartz.Scheduler;
import org.quartz.Trigger;
import org.quartz.impl.StdSchedulerFactory;

import java.util.concurrent.TimeUnit;

import static org.quartz.JobBuilder.newJob;
import static org.quartz.SimpleScheduleBuilder.simpleSchedule;
import static org.quartz.TriggerBuilder.newTrigger;

/**
 * @author cgx
 * @Date 2021/11/19 17:30
 */
public class _07_SchedulerTrigger {

    public static void main(String[] args) {
        try {
            Scheduler scheduler = new StdSchedulerFactory().getScheduler();
            scheduler.start();
            JobDetail job = newJob(helloQuartz.class)
                    .withIdentity("job","group1")
                    .storeDurably()
                    .build();

            Trigger trigger = newTrigger()
                    .withIdentity("trigger","group1")
                    .forJob("job","group1")
                    .startNow()
                    .withSchedule(simpleSchedule()
                            .withIntervalInSeconds(3)
                            .withRepeatCount(1))
//                            .repeatForever())
                    .build();
            scheduler.addJob(job,false);
            scheduler.scheduleJob(trigger);
            TimeUnit.SECONDS.sleep(3);
            scheduler.shutdown();
        }catch (Exception e){

        }
    }
}
